var api = require('../../../../config/api.js');
var util = require('../../../../utils/util.js');
var user = require('../../../../utils/user.js');

var app = getApp();
Page({
  data: {
    username: '',
    password: '',
    code: ''
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    // 页面渲染完成
    var that = this;
    if (options.username) {
      that.setData({
        username: options.username
      })
    }
  },
  onReady: function () {

  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭

  },
  bangding: function () {
    var that = this;

    if (this.data.password.length < 1 || this.data.username.length < 1) {
      wx.showModal({
        title: '错误信息',
        content: '请输入账号和密码',
        showCancel: false
      });
      return false;
    }
    util.request(api.MyAccountbangding,{
      username: that.data.username,
      password: that.data.password
    },'POST').then(function(res) {
      if (res.result==1) {
        wx.switchTab({
          url: '/pages/ucenter/index/index'
        });
      } else {
        util.showErrorToast('账号绑定失败');
      }
    });
  },
  bindUsernameInput: function (e) {
    this.setData({
      username: e.detail.value
    });
  },
  bindPasswordInput: function (e) {
    this.setData({
      password: e.detail.value
    });
  },
  bindCodeInput: function (e) {

    this.setData({
      code: e.detail.value
    });
  }
})